﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using $safeprojectname$.Infrastructure;
using $safeprojectname$.Infrastructure.Factories;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using ProjectBase.Core;

namespace $safeprojectname$.Core.Extensions
{
    [TestClass]
    public class ExtensionsForReporterTest : TestBase
    {
        [TestMethod]
        public void PublishException_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            new PublishingReporter().ReportFatal();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "ExceptionMessage");
            Assert.IsTrue(result.ExceptionObject.Message == "MyException");
        }

        [TestMethod]
        public void PublishInfo_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            var reporter = new PublishingReporter();
            reporter.ReportInfo();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Info");
        }

        [TestMethod]
        public void PublishInfoDelegate_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            var reporter = new PublishingReporter();
            reporter.ReportInfoDelegate();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Info Delegate");
        }

        [TestMethod]
        public void PublishDebug_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            var reporter = new PublishingReporter();
            reporter.ReportDebug();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Debug");
        }

        [TestMethod]
        public void PublishDebugDelegate_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            var reporter = new PublishingReporter();
            reporter.ReportDebugDelegate();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Debug Delegate");
        }

        [TestMethod]
        public void PublishWarning_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            new PublishingReporter().ReportWarning();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Warning");
        }

        [TestMethod]
        public void PublishWarningDelegate_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            new PublishingReporter().ReportWarningDelegate();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Warning Delegate");
        }

        [TestMethod]
        public void PublishError_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            new PublishingReporter().ReportError();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Error");
        }

        [TestMethod]
        public void PublishErrorDelegate_Passed()
        {
            var appender = LoggingTargets.GetCurrentMemoryAppender();
            appender.Clear();

            new PublishingReporter().ReportErrorDelegate();

            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage Error Delegate");
        }

        #region Init

        // You can use the following additional attributes as you write your tests:

        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }

        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }

        [TestInitialize]
        public override void MyTestInitialize()
        {
            PublishingManager.Shutdown();
            PublishingManager.Publish(null, null, null);
            base.MyTestInitialize(); // Use TestInitialize to run code before running each test
        }

        [TestCleanup]
        public override void MyTestCleanup()
        {
            PublishingManager.Shutdown();
            base.MyTestCleanup(); // Use TestCleanup to run code after each test has run
        }
        #endregion Init
    }
}
